'    Copyright 2008 Jan Molnar <jan.molnar@abds.de>
'
'    This file is part of JCQ.

'    JCQ is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    JCQ is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with JCQ. If not, see <http://www.gnu.org/licenses/>.

Public Class Snac1303
    Inherits Snac

    Public Sub New()
        MyBase.New(&H13, &H3)
    End Sub

    Private _MaxItemNumbers As New TlvMaxItemNumbers
    Public ReadOnly Property MaxItemNumbers() As TlvMaxItemNumbers
        Get
            Return _MaxItemNumbers
        End Get
    End Property

    Public Overrides Function CalculateDataSize() As Integer
        Throw New NotImplementedException
    End Function

    Public Overrides Sub Deserialize(ByVal data As System.Collections.Generic.List(Of Byte))
        MyBase.Deserialize(data)

        Dim index As Integer = Snac.SizeFixPart

        Do While index < data.Count
            Dim desc As TlvDescriptor = TlvDescriptor.GetDescriptor(index, data)

            Select Case desc.TypeId
                Case &H4
                    _MaxItemNumbers.Deserialize(data.GetRange(index, desc.TotalSize))
            End Select

            index += desc.TotalSize
        Loop

        Me.SetTotalSize(index)
    End Sub

    Public Overrides Function Serialize() As System.Collections.Generic.List(Of Byte)
        Throw New NotImplementedException
    End Function

End Class

Public Class TlvMaxItemNumbers
    Inherits Tlv

    Public Sub New()
        MyBase.New(&H4)
    End Sub

    Public Overrides Function CalculateDataSize() As Integer

    End Function


    Private _MaxContacts As Integer
    Public Property MaxContacts() As Integer
        Get
            Return _MaxContacts
        End Get
        Set(ByVal value As Integer)
            _MaxContacts = value
        End Set
    End Property

    Private _MaxGroups As Integer
    Public Property MaxGroups() As Integer
        Get
            Return _MaxGroups
        End Get
        Set(ByVal value As Integer)
            _MaxGroups = value
        End Set
    End Property

    Private _MaxVisibleContacts As Integer
    Public Property MaxVisibleContacts() As Integer
        Get
            Return _MaxVisibleContacts
        End Get
        Set(ByVal value As Integer)
            _MaxVisibleContacts = value
        End Set
    End Property

    Private _MaxInvisibleContacts As Integer
    Public Property MaxInvisibleContacts() As Integer
        Get
            Return _MaxInvisibleContacts
        End Get
        Set(ByVal value As Integer)
            _MaxInvisibleContacts = value
        End Set
    End Property

    Private _MaxVisibleInvisibleBitmasks As Integer
    Public Property MaxVisibleInvisibleBitmasks() As Integer
        Get
            Return _MaxVisibleInvisibleBitmasks
        End Get
        Set(ByVal value As Integer)
            _MaxVisibleInvisibleBitmasks = value
        End Set
    End Property

    Private _MaxPresenseInfoFields As Integer
    Public Property MaxPresenseInfoFields() As Integer
        Get
            Return _MaxPresenseInfoFields
        End Get
        Set(ByVal value As Integer)
            _MaxPresenseInfoFields = value
        End Set
    End Property

    Private _MaxIgnoreListEntries As Integer
    Public Property MaxIgnoreListEntries() As Integer
        Get
            Return _MaxIgnoreListEntries
        End Get
        Set(ByVal value As Integer)
            _MaxIgnoreListEntries = value
        End Set
    End Property

    Public Overrides Function Serialize() As System.Collections.Generic.List(Of Byte)
        Throw New NotImplementedException
    End Function

    Public Overrides Sub Deserialize(ByVal data As System.Collections.Generic.List(Of Byte))
        MyBase.Deserialize(data)

        Dim index As Integer = Tlv.SizeFixPart

        _MaxContacts = ByteConverter.ToUInt16(data.GetRange(index, 2))
        index += 2

        _MaxGroups = ByteConverter.ToUInt16(data.GetRange(index, 2))
        index += 2

        _MaxVisibleContacts = ByteConverter.ToUInt16(data.GetRange(index, 2))
        index += 2

        _MaxInvisibleContacts = ByteConverter.ToUInt16(data.GetRange(index, 2))
        index += 2

        _MaxPresenseInfoFields = ByteConverter.ToUInt16(data.GetRange(index, 2))
        index += 2

        index += 2 * 8

        _MaxIgnoreListEntries = ByteConverter.ToUInt16(data.GetRange(index, 2))
    End Sub

End Class